﻿using Socium.Domain.Collections;
using Socium.Domain.Persons;
using Socium.Domain.Tests;
using Socium.Domain.Tests.Testings;

namespace Socium.Testings {
	class MultipleVariantTreeItem : MultipleVariantTreeItemBase {
		public MultipleVariantTreeItem(Variant variant) : base(variant.Text) {
			_variant = variant;
		}

		readonly Variant _variant;
		
		public override void Save(Person person, Testing testing) {
			testing.RemoveAnswers(person, _variant);
			if (IsSelected) {
				testing.AddAnswer(new ClosedAnswer(person, _variant));
			}
		}

		public override void Load(Person person, Testing testing) {
			IsSelected = !testing.FindAnswers(person, _variant).IsEmpty();
		}
	}
}
